package com.edu.bhu.admin.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.bhu.admin.mapper.HouRecordMapper;
import com.edu.bhu.admin.domain.HouRecord;
import com.edu.bhu.admin.service.IHouRecordService;
import com.edu.bhu.common.core.text.Convert;

import static com.edu.bhu.admin.util.rentStatusUtil.changeStatus;

/**
 * 租房记录Service业务层处理
 * 
 * @author zhangkeyi
 * @date 2022-02-22
 */
@Service
public class HouRecordServiceImpl implements IHouRecordService 
{
    @Autowired
    private HouRecordMapper houRecordMapper;

    /**
     * 查询租房记录
     * 
     * @param recordId 租房记录主键
     * @return 租房记录
     */
    @Override
    public HouRecord selectHouRecordByRecordId(Long recordId)
    {
        return houRecordMapper.selectHouRecordByRecordId(recordId);
    }

    /**
     * 查询租房记录列表
     * 
     * @param houRecord 租房记录
     * @return 租房记录
     */
    @Override
    public List<HouRecord> selectHouRecordList(HouRecord houRecord)
    {
        return houRecordMapper.selectHouRecordList(houRecord);
    }
    /**
     * 查询租房记录列表(关联明细)
     *
     * @param houRecord 租房记录
     * @return 租房记录集合
     */
    public List<HouRecord> selectHouRecordListWithDetail(HouRecord houRecord)
    {
        List<HouRecord> list = houRecordMapper.selectHouRecordListWithDetail(houRecord);
        //将租赁信息加入字段
        list.stream().map(item ->{
            HouRecord houRecord1 = changeStatus(item);
            return houRecord1;
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 新增租房记录
     * 
     * @param houRecord 租房记录
     * @return 结果
     */
    @Override
    public int insertHouRecord(HouRecord houRecord)
    {
        return houRecordMapper.insertHouRecord(houRecord);
    }

    /**
     * 修改租房记录
     * 
     * @param houRecord 租房记录
     * @return 结果
     */
    @Override
    public int updateHouRecord(HouRecord houRecord)
    {
        return houRecordMapper.updateHouRecord(houRecord);
    }

    /**
     * 批量删除租房记录
     * 
     * @param recordIds 需要删除的租房记录主键
     * @return 结果
     */
    @Override
    public int deleteHouRecordByRecordIds(String recordIds)
    {
        return houRecordMapper.deleteHouRecordByRecordIds(Convert.toStrArray(recordIds));
    }

    /**
     * 删除租房记录信息
     * 
     * @param recordId 租房记录主键
     * @return 结果
     */
    @Override
    public int deleteHouRecordByRecordId(Long recordId)
    {
        return houRecordMapper.deleteHouRecordByRecordId(recordId);
    }

    /**
     * 删除租房记录信息(houseId)
     *
     * @param houseId 房屋Id
     * @return 结果
     */
    public int deleteHouRecordByHouseId(Long houseId){
        return houRecordMapper.deleteHouRecordByHouseId(houseId);
    }
}
